<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
	<?php $this->load->view('common/top', array('title' => 'SEWIKI - CREATE NEW BOOK')); ?>
			<link rel="stylesheet" type="text/css" href="<?=base_url(). 'static/css/jquery.ui.core.css'?>"/>
			<link rel="stylesheet" type="text/css" href="<?=base_url(). 'static/css/jquery.ui.datepicker.css'?>"/>
			<link rel="stylesheet" type="text/css" href="<?=base_url(). 'static/css/jquery.ui.theme.css'?>"/>
			<script type="text/javascript" src="<?=base_url() . 'static/js/jquery.ui.core.js'?>"></script>
			<script type="text/javascript" src="<?=base_url() . 'static/js/jquery.ui.widget.js'?>"></script>
			<script type="text/javascript" src="<?=base_url() . 'static/js/jquery.ui.datepicker.js'?>"></script>
	<body>
		<div id="container">
			<?php $this->load->view('common/header'); ?>
			<div id="content">
				<script src="<?=base_url() . 'static/js/jquery.validate.js'?>" type="text/javascript"></script>
				<script type="text/javascript">
					$(function() {
						var num_rows = 1;
						var max_rank = <?=$max_rank?>;
						
						$("#cdead").datepicker({minDate: +1});
						$("#cdep_num").attr({value:num_rows});
						$("#add_dep_title").attr({rowspan:num_rows + 1});
						
						$("#add_dep_button").click(function() {
							num_rows ++;
							
							var selects  = "<tr><td><select name=\"cdep_" + (num_rows).toString() + "\">" + "<?php echo '<option value=\"-1\"></option>';?><?php for($i = 1; $i <= $max_rank; $i ++):?><?php echo '<option value=\"' . strval($i) . '\">依赖于第' . strval($i) . '章</option>' ?><?php endfor; ?><?php echo '</select></td></tr>'?>";
							
							$("#add_dep_title").attr({rowspan:num_rows + 1});
							$("#add_dep_bottom").before(selects);
							$("#cdep_num").attr({value:num_rows});
						});
					});
				</script>
				<?php $this->load->view('common/menu'); ?>
				<div id="main">
					<div id="create_chapter_form_title" class="title">
						创建新章节
					</div>
					<div id="create_chapter_form" class="text_form">
						<?php echo form_open('', array('id' => 'create_chapter_form_entity')); ?>
							<table width="100%">
								<tr>
									<td><?php echo form_label('章节名', 'ctitle');?></td>
									<td><?php echo form_input(array(
										'name'  => 'ctitle',
										'style' => 'width:90%')); ?></td>
								</tr>
								<tr>
									<td><?php echo form_label('章节描述', 'cdesc'); ?></td>
									<td><?php echo form_textarea(array(
										'name'  => 'cdesc',
										'style' => 'width:90%')); ?></td>
								</tr>
								<tr>
									<td><?php echo form_label('章节排序', 'crank'); ?></td>
									<td>
										<select name="crank">
											<option value="0">在最前</option>
											<?php for($i = 1; $i <= $max_rank; $i ++):?>
												<option value="<?=$i?>">在第<?=$i?>章之后</option>
											<?php endfor; ?>
										</select>
									</td>
								</tr>
								<tr>
									<td><?php echo form_label('章节截止日期', 'cdead'); ?></td>
									<td><input id="cdead" name="cdead" type="text" /></td>
								</tr>
								<?php // 如果还没有章节，不显示章节依赖 ?>
								<?php if($max_rank > 0): ?>
								<tr>
									<td id="add_dep_title"><?php echo form_label('章节依赖', 'cdepend'); ?></td>
									<td>
										<select name="cdep_0">
											<option value="0" selected="1"></option>
											<?php for($i = 1; $i <= $max_rank; $i ++):?>
												<option value="<?=$i?>">依赖于第<?=$i?>章</option>
											<?php endfor; ?>
										</select>
									</td>
								</tr>
								<tr id="add_dep_bottom">
									<td style="vertical-align:top;">
										<?=form_button(array(
											'id'      => 'add_dep_button',
											'content' => '添加一个章节依赖'))?>
										<input name="cdep_num" id="cdep_num" type="hidden"/>
									</td>
								</tr>
								<?php endif; ?>
								<tr>
									<td colspan="2" style="text-align:center">
										<?php echo form_submit('submit', '提交') ?>
										<?php echo form_reset('reset', '重置') ?>
									</td>
								</tr>
							</table>
						<?php echo form_close(); ?>
					</div>
				</div>
			</div>
			<?php $this->load->view('common/footer'); ?>
		</div>
	</body>
</html>